Skip to content

lib: add utf16 fast path for TextDecoder#61559

Draft
ChALkeR wants to merge 2 commits intonodejs:mainfrom
ChALkeR:chalker/decoder/unify/3
Draft

lib: add utf16 fast path for TextDecoder#61559
ChALkeR wants to merge 2 commits intonodejs:mainfrom
ChALkeR:chalker/decoder/unify/3

Conversation

@ChALkeR
Copy link
Member

@ChALkeR ChALkeR commented Jan 28, 2026

Tracking: #61041

Better reviewed with whitespace hidden.

Builds on top of #61549
Like that PR, this is based on the logic in https://github.com/ExodusOSS/bytes

Previously, ICU and string_decoder were used on with-intl and without-intl variants correspondingly for UTF-16 implementation. ICU path was slow, string_decoder path was wrong and lacked BE anyway.

Instead, just use the codepath from #61549 with simple UTF-16 decoding methods.

This:

  1. Speeds up utf-16le decoding about 3x
  2. Speeds up utf-16be decoding about 2x
  3. Adds fatal utf-16le support to without-intl TextDecoder
  4. Fixes utf-16le replacement for without-intl TextDecoder, previously it was silently returning wrong results
  5. Adds utf-16be support (both fatal and replacement) to without-intl TextDecoder
  6. Unifies the logic, using a single codepath everywhere for Unicode

Benchmarks

https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1804/

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/performance
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. needs-ci PRs that need a full CI run. labels Jan 28, 2026
@ChALkeR ChALkeR force-pushed the chalker/decoder/unify/3 branch 4 times, most recently from 6fa26ff to 9e26e23 Compare January 28, 2026 06:41
@ChALkeR ChALkeR added the needs-benchmark-ci PR that need a benchmark CI run. label Jan 28, 2026
@ChALkeR ChALkeR force-pushed the chalker/decoder/unify/3 branch 2 times, most recently from 398a94e to 2a30acc Compare February 2, 2026 04:18
@ChALkeR ChALkeR marked this pull request as ready for review February 2, 2026 04:21
@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.70%. Comparing base (4f13746) to head (b1f8aa3).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61559      +/-   ##
==========================================
- Coverage   89.72%   89.70%   -0.02%     
==========================================
  Files         675      675              
  Lines      204806   204824      +18     
  Branches    39355    39355              
==========================================
- Hits       183761   183738      -23     
- Misses      13330    13363      +33     
- Partials     7715     7723       +8     
Files with missing lines Coverage Δ
lib/internal/encoding.js 99.83% <100.00%> (-0.17%) ⬇️
lib/internal/encoding/util.js 100.00% <100.00%> (ø)

... and 43 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ChALkeR ChALkeR marked this pull request as draft February 2, 2026 06:52
@ChALkeR ChALkeR force-pushed the chalker/decoder/unify/3 branch from 2a30acc to 60a1400 Compare February 18, 2026 02:46
@ChALkeR ChALkeR marked this pull request as ready for review February 18, 2026 03:56
@ChALkeR ChALkeR force-pushed the chalker/decoder/unify/3 branch 2 times, most recently from d88096e to 4a91b6f Compare February 18, 2026 11:01
@ChALkeR ChALkeR force-pushed the chalker/decoder/unify/3 branch from 4a91b6f to b1f8aa3 Compare February 18, 2026 11:02
@ChALkeR ChALkeR added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2026
Comment on lines +5 to +6
const MAX_N = 256 * 1024;
const TOTAL_SIZE = 256 * 1024 * 1024;
Copy link
Member Author

@ChALkeR ChALkeR Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite slow esp when run 30 times on CI
I wanted to denoise it though as otherwise it's still noisy even on e.g. 2x less numbers
If slow benchmarks are an issue I can exclude this change

@ChALkeR ChALkeR added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Feb 18, 2026
@ChALkeR ChALkeR marked this pull request as draft February 18, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. needs-benchmark-ci PR that need a benchmark CI run. needs-ci PRs that need a full CI run. request-ci Add this label to start a Jenkins CI on a PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments